package org.moda.sql.visitor;

import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.SelectItem;

/**
 * @ClassName: SelectItemVisitor
 * @Description:
 * @Author: xuanyang
 * @Date: 2024-11-24 23:40
 * @Version: 1.0
 **/
public class SelectItemVisitor {
    public static SelectItemInfo selectItem(SelectItem<?> selectItem) {
        Expression expression = selectItem.getExpression();

        return switch(expression) {
            case AllColumns allColumns -> new SelectItemInfo.SelectAll();
            case Column column -> new SelectItemInfo.SelectColumn(column.getColumnName(), column.getFullyQualifiedName());
            default -> new SelectItemInfo.SelectExpression("", "");
        };
    }
}
